#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 12;

int dp[N][N][N][N];
int g[N][N];
int n;

int main()
{
    cin >> n;

    int a, b, c;
    while (cin >> a >> b >> c, a && b && c)
        g[a][b] = c;

    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++)
            for (int k = 1; k <= n; k ++)
                for (int l = 1; l <= n; l ++)
                {
                    int t1 = max(dp[i][j - 1][k][l - 1], dp[i - 1][j][k][l - 1]);
                    int t2 = max(dp[i][j - 1][k - 1][l], dp[i - 1][j][k - 1][l]);
                    if (i == k && j == l)
                        dp[i][j][k][l] = max(t1, t2) + g[i][j];
                    else
                        dp[i][j][k][l] = max(t1, t2) + g[i][j] + g[k][l];
                }

    cout << dp[n][n][n][n] << endl;

    return 0;
}